<template>
  <!-- <div>测试组价33333
    <img src="../../icons/svg/pm-test.svg" alt="">
    </div> -->
  <div style="width: 100%">
    <template>
      <div v-if="mode === 'edit'">
        <div v-if="cardList && cardList.length > 0">
          <div v-for="item in cardList" :key="item">
            <el-row>
              <el-col>
                <el-card :body-style="{ padding: '0px' }">
                  <img
                    :src="item.url"
                    :style="{
                      width: cardWidth + 'px',
                      height: cardHeight + 'px',
                    }"
                  />
                  <div style="padding: 14px">
                    <span>{{ item.title }}</span>
                    <div class="bottom clearfix">
                      <time class="time">{{ item.desc }}</time>
                      <!-- <el-button type="text" class="button">操作按钮</el-button> -->
                    </div>
                  </div>
                </el-card>
              </el-col>
            </el-row>
          </div>
        </div>
        <div v-else>
          <el-row>
            <el-col>
              <el-card :body-style="{ padding: '0px' }">
                <img
                  :src="cardUrl"
                  :style="{
                    width: cardWidth + 'px',
                    height: cardHeight + 'px',
                  }"
                />
                <div style="padding: 14px">
                  <span>{{ cardtitle }}</span>
                  <div class="bottom clearfix">
                    <time class="time">{{ carddesc }}</time>
                    <!-- <el-button type="text" class="button">操作按钮</el-button> -->
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>
      </div>
      <div v-else>
        {{ value }}
      </div>
    </template>
  </div>
</template>
<script>
import datasource from "../../mixins/steps-datasource";
export default {
  name: "pm-card",
  mixins: [datasource],
  props: {
    value: {
      type: String | Number | Object | Array,
    },
    mode: {
      // 编辑态: edit, 查看态:view , 用于在子表格内切换状态
      default: "edit",
    },
    entityModel: {
      // 如果组件绑定了一个实体, 则该属性会传入实体的数据
      default: () => {},
    },
    readonly: {
      default: false,
    },
    disabled: {
      default: false,
    },
    cardtitle: {
      default: "好吃的汉堡",
    },
    cardUrl: {
      default:
        "https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png",
    },
    carddesc: {
      default: "描述说明",
    },
    cardWidth: {
      default: "",
    },
    cardHeight: {
      default: "",
    },
  },
  icon: "",
  viewId: {},
  viewCode: {
    default: "view",
  },
  data() {
    return {
      cardList: [],
    };
  },
  mounted() {
    console.log(this.value, "this.value");
    if (this.value) {
      this.cardtitle = this.value;
      if (this.mode == "view") {
        this.disabled = true;
      }
    }
  },
  methods: {},
  watch: {
    options: {
      immediate: true,
      deep: true,
      handler(val) {
        if (val && val.length) {
          this.cardList = val.map((item) => {
            return {
              url: item._data.url,
              title: item._data.title,
              desc: item._data.desc,
            };
          });
        }
      },
    },
  },
};
</script>
<style scoped>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

/* .image {
  width: 100px;
  display: block;
} */

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
</style>
